package cn.byapps.controller;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.byapps.entity.Book;
import cn.byapps.service.BookService;

@Controller
public class HelloController {

	@Resource
	private BookService bookService;

	@RequestMapping("/")
	public String hi(Model model) {
		model.addAttribute("hello", "你好");
		List<Book> list = bookService.findAll();
		model.addAttribute("list", list);
		return "hi";
	}

	@RequestMapping("/hi")
	public String hii(Model model) {
		model.addAttribute("hello", "你好");
		List<Book> list = bookService.findAll();
		model.addAttribute("list", list);
		return "hi/hi";
	}

	@ResponseBody
	@RequestMapping("/hello")
	public String hello() {
		Book book = new Book();
		book.setName("SSSS");
		bookService.save(book);
		return "你好";
	}

	@ResponseBody
	@RequestMapping("/hello2")
	public List<Book> hello2() {
		List<Book> list = new ArrayList<>();
		Book book = new Book();
		book.setName("SSSS");
		list.add(book);
		return list;
	}
}
